home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / xlib06p2 / demo2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-23  |  6.5 KB  |  212 lines

  1. /*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap,  conventional
  6. masked planar bitmap, and video bitmap blits.
  7.  
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <malloc.h>
  17. #include <dos.h>
  18. #include <time.h>
  19. #include "xlib.h"
  20. #include "xcbitmap.h"
  21. #include "xpbitmap.h"
  22. #include "xvbitmap.h"
  23. #include "xbmtools.h"
  24. #include  "xtext.h"
  25. #include  "xrect.h"
  26. #include  "xrect.h"
  27.  
  28. /* Macro to make pointer parameters model independent */
  29. //#define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  30.  
  31. char turtle[] = {
  32.     20,30,
  33. /*  |      .       |       .      |       .      |      .       */
  34.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  39.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  40.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  41.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  42.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  43.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  44.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  45.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  46.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  47.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  48.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  49.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  50.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  51.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  52.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  53.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  54.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  61.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  62.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  63.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  64.     };
  65.  
  66.  
  67. char *pbm, *vbm;
  68. char *newfnt;
  69.  
  70. char *
  71. AllocatedSprite(int width, int height, int logical_width, char * bitmap)
  72. {
  73.     char * result;
  74.     int size;
  75.  
  76.     pbm = (char *)malloc(width * height + 2);
  77.     x_bm_to_pbm(bitmap,pbm);
  78.  
  79.     result = (char *)malloc((width * height * 7) / 2 + 1025);
  80.     if (result == 0)
  81.         return(0);
  82.     size = x_compile_bitmap(logical_width, bitmap, result);
  83.  
  84.     return (char *)realloc(result, size);
  85. }
  86.  
  87.  
  88.  
  89. void load_user_fonts(){
  90.   FILE *f;
  91.   int i; char c;
  92.   f=fopen("c:\\font.fnt","rb");
  93.   f=fopen("smalthin.fnt","rb");
  94.   newfnt = (char *)malloc( 676 );
  95.   for (i=0;i< 676;i++){
  96.     fread(&c,1,1,f);
  97.     *(newfnt+i)=c;
  98.   }
  99.   fclose(f);
  100.   x_text_init();
  101.   x_register_userfont((BYTE *)newfnt);
  102.   x_set_font(2);
  103. }
  104.  
  105. void
  106. main()
  107. {
  108.     int i,j,k;
  109.  
  110.     double ratio,ratio2;
  111.     clock_t pbm_t0,pbm_t1,cbm_t0,cbm_t1,vbm_t0,vbm_t1;
  112.     long vbm_ticks,pbm_ticks,cbm_ticks;
  113.     char  * TurtleSprite;
  114.  
  115.     x_set_mode(X_MODE_320x240,368);
  116.  
  117.     TurtleSprite = AllocatedSprite(20, 30, 92, turtle);
  118.  
  119. //    vbm = x_make_vbm(turtle,&NonVisual_Offs);
  120. //    if (!vbm) {
  121. //      sound(1000);
  122. //      delay(100);
  123. //      nosound();
  124. //    }
  125.  
  126.     load_user_fonts();
  127.     x_bgprintf(0,0,0,14,0,
  128.           "This is a demo to show the speed difference between");
  129.     x_bgprintf(0,8,0,14,0,
  130.           "compiled, planar and video bitmaps.  The bitmap:");
  131.  
  132.     x_put_cbitmap(140, 18, 0, TurtleSprite);
  133.  
  134.     x_bgprintf(0,48,0,14,0,
  135.           "This demo uses the NON CLIPPED, MASKED versions of");
  136.     x_bgprintf(0,56,0,14,0,
  137.            "       'PBM' and VBM' put functions");
  138.     x_bgprintf(0,78,0,14,0,
  139.           "Press a key to start with PLANAR BITMAP demo");
  140.  
  141.     getch();
  142.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  143.  
  144.  
  145.     pbm_t0 = clock();
  146.     for (k=0;k<3;k++)
  147.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  148.         for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  149.           x_put_masked_pbm(i*20, j*30, 0, (BYTE *)pbm);
  150.     pbm_t1 = clock();
  151.     pbm_ticks = pbm_t1 - pbm_t0; 
  152. /*
  153.     x_bgprintf(0,0,0,14,0,
  154.           "Press a key to start with the VIDEO BITMAP demo");
  155.  
  156.     getch();
  157.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  158.  
  159.  
  160.     gettime(&vbm_t0);
  161.     for (k=0;k<3;k++)
  162.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  163.         for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  164.           x_put_masked_vbm(i*20, j*30, 0, vbm);
  165.     gettime(&vbm_t1);
  166.     vbm_ticks = (((long)vbm_t1.ti_hund
  167.                 +((long)vbm_t1.ti_sec*100)
  168.                 +((long)vbm_t1.ti_min*6000)) -
  169.                 (((long)vbm_t0.ti_hund
  170.                 +((long)vbm_t0.ti_sec*100)
  171.                 +((long)vbm_t0.ti_min*6000))));
  172.  
  173. */
  174.  
  175.  
  176.     x_bgprintf(0,0,0,14,0,
  177.           "Now Press a key to start with COMPILED BITMAP demo");
  178.  
  179.     getch();
  180.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  181.  
  182.     cbm_t0 = clock();
  183.     for (k=0;k<3;k++)
  184.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  185.         for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  186.           x_put_cbitmap(i*20, j*30, 0, TurtleSprite);
  187.     cbm_t1 = clock();
  188.     cbm_ticks = cbm_t1 - cbm_t0; 
  189.     if (cbm_ticks==0){
  190.       cbm_ticks=1;
  191.       pbm_ticks+=1;
  192.       vbm_ticks+=1;
  193.     }
  194.     ratio = pbm_ticks*(double)1.0/cbm_ticks;
  195. //    ratio2 = vbm_ticks*(double)1.0/cbm_ticks;
  196.  
  197.     x_set_font(1);
  198.     x_bgprintf(0,ScrnPhysicalHeight-30,0,14,0,
  199.           "s/100 PBM=%ld CBM=%ld - %4.1lf:1",
  200.           pbm_ticks, cbm_ticks,ratio,ratio2);
  201.     x_set_font(2);
  202.     x_bgprintf(0,ScrnPhysicalHeight-16,0,14,0,
  203.           "Timing is rough but still,  quite impressive ! ");
  204.     x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
  205.           "Clipping slows things down considerably. ");
  206.  
  207.  
  208.     getch();
  209.     x_text_mode();
  210. }
  211.  
  212.